package com.cloud.business.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.business.dto.SaveDTO;
import com.cloud.business.dto.SelectDTO;
import com.cloud.business.entity.DemoClientTable;
import com.cloud.business.mapper.DemoMapper;
import com.cloud.business.service.DemoService;
import org.springframework.stereotype.Service;

@Service
public class DemoServiceImpl extends ServiceImpl<DemoMapper, DemoClientTable> implements DemoService {
    @Override
    public Page<DemoClientTable> selectList(SelectDTO dto) {
        LambdaQueryWrapper<DemoClientTable> queryWrapper = Wrappers.lambdaQuery(DemoClientTable.class);
        queryWrapper.eq(StrUtil.isNotEmpty(dto.getName()), DemoClientTable::getName, dto.getName());
        return this.page(dto.getPage(), queryWrapper);
    }

    @Override
    public boolean save(SaveDTO saveDTO) {
        DemoClientTable demo = BeanUtil.toBean(saveDTO, DemoClientTable.class);
        return this.save(demo);
    }
}
